package com.vibration.matlab;

import com.mathworks.toolbox.javabuilder.MWClassID;
import com.mathworks.toolbox.javabuilder.MWException;
import com.mathworks.toolbox.javabuilder.MWNumericArray;
import com.mathworks.toolbox.javabuilder.MWStructArray;
import opt_cal.GetOptParameters;

import java.beans.IntrospectionException;

/**
 * 得到最终数据
 */
public class GetFinalData {

    /**
     *
    得到最终数据 function [HVopt,DCopt,aopt,mod,A,L2i1,DCT,HVT,T1,Tfin,Cont,ER,DATERROR]
     */
    public static TransInfo getFinalData(A a, C c, G g, double[][] Tinv, double TSAM, int MM, Cont cont, double[][] aopt,
                                         double[][] L2i1, double[][] Tfin, double[][] Tfin2, double T1, double[][] mac, double[][] ini1, double[][] HVopt) throws MWException, IntrospectionException {
        //传输载体
        TransInfo transInfo=new TransInfo();
        GetOptParameters getOptParameters=new GetOptParameters();
        //转化结构体
        MWStructArray matA = MWStructArray.fromBean(a);
        MWStructArray matC = MWStructArray.fromBean(c);
        MWStructArray matG = MWStructArray.fromBean(g);
        //转换矩阵Tinv
        MWNumericArray matTinv = new MWNumericArray(Tinv, MWClassID.DOUBLE);
        MM=1;
        //转换结构体
        MWStructArray matCont = MWStructArray.fromBean(cont);
        //转换矩阵
        MWNumericArray matAopt = new MWNumericArray(aopt, MWClassID.DOUBLE);
        MWNumericArray matL2i1 = new MWNumericArray(L2i1, MWClassID.DOUBLE);
        MWNumericArray matTfin = new MWNumericArray(Tfin, MWClassID.DOUBLE);
        MWNumericArray matTfin2 = new MWNumericArray(Tfin2, MWClassID.DOUBLE);
        MWNumericArray matmac = new MWNumericArray(mac, MWClassID.DOUBLE);
        MWNumericArray matini1 = new MWNumericArray(ini1, MWClassID.DOUBLE);
        MWNumericArray matL2optimo = new MWNumericArray(a.getL2optimo(), MWClassID.DOUBLE);
        MWNumericArray matProbLimSupSegHHS = new MWNumericArray(a.getProbLimSupSegHHS(), MWClassID.DOUBLE);
        MWNumericArray matLimVelSegHHS = new MWNumericArray(a.getLimVelSegHHS(), MWClassID.DOUBLE);

        Object[] res=getOptParameters.opt_cal(13,matA,matC,matG,matTinv,TSAM,MM,matCont,matAopt,matL2i1,matTfin,matTfin2,T1,matmac,matini1,a.getNsubiter()[0][0],a.getNiter()[0][0],matL2optimo,a.getNiterf()[0][0],
                matProbLimSupSegHHS,matLimVelSegHHS,File.modPath,File.ffrecPath,File.HVCPath
        );
        /**
         * 拿参数HVopt  0位
         */
        MWNumericArray getHVopt= (MWNumericArray)res[0];
        HVopt=(double[][]) getHVopt.toDoubleArray();

        /**
         * 拿参数aopt 拿2位
         */
        MWNumericArray getAopt= (MWNumericArray)res[2];
        aopt=(double[][]) getAopt.toDoubleArray();

        transInfo.setAopt(aopt);
        transInfo.setHVopt(HVopt);
        return transInfo;
    }

}
